package com.iqi.onigao.module.user;

import java.util.List;

import com.iqi.onigao.context.Bean;
import com.iqi.onigao.module.ErrorCheck;

import cn.hutool.core.util.RandomUtil;
import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import net.IClient;
import net.Package;
import si.client.CPlayer;
import si.client.CUser;
import si.pod.RoleInfoPOD;
@Bean(UserBO.class)
public class UserBOImpl extends CUser implements UserBO {
	static final Log log = LogFactory.get(UserBOImpl.class);
	@Override
	public boolean validateUUIDResult(IClient session, Package p, int code, List<RoleInfoPOD> roles,
			int recommandJobId) {
		ErrorCheck.check(session, code);
		
		// 选取一个角色
		RoleInfoPOD role = null;
		for (RoleInfoPOD roleInfoPOD : roles) {
			role = roleInfoPOD;
			break;
		}
		
		if (role == null) {
			// 创建角色
			CUser.createRole(session, 1001, RandomUtil.randomString(8));
		}else {
			// 登录角色
			CUser.chooseRole(session, role.getPid());
		}
		return false;
	}

	@Override
	public boolean chooseRoleResult(IClient session, Package p, int code) {
		ErrorCheck.check(session, code);
		// 加载数据
		CPlayer.loadPlayer(session);
		return false;
	}

	@Override
	public boolean createRoleResult(IClient session, Package p, int code, RoleInfoPOD role) {
		ErrorCheck.check(session, code);
		// 登录角色
		CUser.chooseRole(session, role.getPid());
		return false;
	}

	@Override
	public boolean pang(IClient session, Package p, int serverTime) {
		return false;
	}

	@Override
	public boolean logoutResult(IClient session, Package p, int code) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean notifyError(IClient session, Package p, int code, String msg) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean notifyServerStatus(IClient session, Package p, int sign, int time) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean selectRoleResult(IClient session, Package p, int code, RoleInfoPOD role) {
		// TODO Auto-generated method stub
		return false;
	}

}
